package com.dxt.rabbitmq.service.DelayAndDead;

import com.dxt.rabbitmq.config.DelayAndDeadConfig;
import com.dxt.rabbitmq.vo.TestMessage;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Service
public class DeadConsumer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RabbitListener(queues = DelayAndDeadConfig.DEAD_QUEUE)
    public void consume(TestMessage testMessage, Channel channel,
                        @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws InterruptedException, IOException {
        System.out.println("DeadConsumer get message...");
        TimeUnit.SECONDS.sleep(20);
        channel.basicAck(tag, true);
    }
}
